const app = require('../app')
const {
	NAME_IS_ALREADY_EXISTS,
	NAME_OR_PASSWORD_IS_REQUIRED,
	NAME_IS_NOT_EXISTS,
	PASSWORD_IS_INCORRENT,
	UNAUTHORIZATION,
	OPERATION_IS_NOT_ALLOWED,
	CREATE_CLUB_ERROR,
	CLUB_IS_ALREADY_EXISTS,
	AUIT_FAILED,
	ADD_CLUD_FAILED,
	DELETE_CLUB_FAILED,
	POST_CREATE_FAILED,
	POST_UPDATE_FAILED,
	POST_REMOVE_FAILED,
	POST_IS_NOT_EXISTS,
	POST_SELECT_FAILED,
	EVENT_CTEATE_FAILED,
	EVENT_REMOVE_FAILED,
	EVENT_UPDATE_FAILED,
	EVENT_SEARCH_FAILED,
	USER_ALREADY_REGISTERED,
	REGISTER_LIMIT,
	UPDATE_EVENT_STATUS_FAILED,
	EVENT_REGISTER_FAILED,
	USER_NOT_REGISTERED,
	EVENT_CANCEL_FAILED,
	COMMENT_PUBLISH_FAILED,
	COMMENT_REPLY_FAILED,
	ADD_CAROUSEL_FAILED,
	REMOVE_CAROUSEL_FAILED,
	UPDATE_CAROUSEL_STATUS_FAILED,
	EMAIL_SEND_FAILED,
	EMAIL_VERIFY_FAILED,
	NAME_OR_PASSWORD_FAILED,
	NAME_OR_EMAIL_IS_REQUIRED
} = require('../config/error')

app.on('error', (error, ctx) => {
	let code = 0
	let message = ''
	switch (error) {
		case NAME_OR_PASSWORD_IS_REQUIRED:
			code = -1001
			message = '用户名或者密码不能为空'
			break
		case NAME_IS_ALREADY_EXISTS:
			code = -1002
			message = '用户名已经存在了'
			break
		case NAME_IS_NOT_EXISTS:
			code = -1003
			message = '用户不存在'
			break
		case PASSWORD_IS_INCORRENT:
			code = -1004
			message = '密码错误请检查'
			break
		case UNAUTHORIZATION:
			code = -1005
			message = '无效的token'
			break
		case NAME_OR_PASSWORD_FAILED:
			code = -1006
			message = '用户名或者密码错误'
			break
		case NAME_OR_EMAIL_IS_REQUIRED:
			code = -1007
			message = '用户名或邮箱有误'
			break
		case OPERATION_IS_NOT_ALLOWED:
			code = -2001
			message = '用户没有操做的权限'
			break
		case CREATE_CLUB_ERROR:
			code = -3001
			message = '创建社团失败'
			break
		case CLUB_IS_ALREADY_EXISTS:
			code = -3002
			message = '社团已经存在'
			break
		case AUIT_FAILED:
			code = -3003
			message = '审核失败'
			break
		case ADD_CLUD_FAILED:
			code = -3004
			message = '加入社团失败'
			break
		case DELETE_CLUB_FAILED:
			code = -3005
			message = '社团不存在'
			break
		case POST_CREATE_FAILED:
			code = -4001
			message = '帖子创建失败'
			break
		case POST_UPDATE_FAILED:
			code = -4002
			message = '帖子更新失败'
			break
		case POST_REMOVE_FAILED:
			code = -4003
			message = '帖子删除失败'
		case POST_IS_NOT_EXISTS:
			code = -4004
			message = '贴子不存在'
			break
		case POST_SELECT_FAILED:
			code = -4005
			message = '帖子查询失败'
			break
		case EVENT_CTEATE_FAILED:
			code = -5001
			message = '活动创建失败'
			break
		case EVENT_REMOVE_FAILED:
			code = -5002
			message = '活动删除失败'
			break
		case EVENT_UPDATE_FAILED:
			code = -5003
			message = '更新活动失败'
			break
		case EVENT_SEARCH_FAILED:
			code = -5004
			message = '查询失败'
			break
		case USER_ALREADY_REGISTERED:
			code = -5005
			message = '用户已经报过名'
			break
		case REGISTER_LIMIT:
			code = -5006
			message = '报名超过上限'
			break
		case UPDATE_EVENT_STATUS_FAILED:
			code = -5007
			message = '修改活动状态失败'
			break
		case EVENT_REGISTER_FAILED:
			code = -5008
			message = '活动报名失败'
			break
		case USER_NOT_REGISTERED:
			code = -5009
			message = '用户还没有报名'
			break
		case EVENT_CANCEL_FAILED:
			code = -5010
			message = '取消报名失败'
			break
		case COMMENT_PUBLISH_FAILED:
			code = -6001
			message = '评论发布失败'
			break
		case COMMENT_REPLY_FAILED:
			code = -6002
			message = '评论回复失败'
			break
		case ADD_CAROUSEL_FAILED:
			code = -7001
			message = '轮播图添加失败'
			break
		case REMOVE_CAROUSEL_FAILED:
			code = -7002
			message = '删除轮播图失败'
			break
		case UPDATE_CAROUSEL_STATUS_FAILED:
			code = -7003
			message = '更新轮播图状态成功'
			break
		case EMAIL_SEND_FAILED:
			code = -8001
			message = '邮箱发送失败'
			break
		case EMAIL_VERIFY_FAILED:
			code = -8002
			message = '验证码错误'
			break
		default:
			code = -10000
			message = '接口出错'
	}
	ctx.body = { code, message }
})
